package com.atguigu.daijia.order.service.impl;

import com.atguigu.daijia.model.entity.order.OrderMonitor;
import com.atguigu.daijia.model.entity.order.OrderMonitorRecord;
import com.atguigu.daijia.order.mapper.OrderMonitorMapper;
import com.atguigu.daijia.order.repository.OrderMonitorRecordRepository;
import com.atguigu.daijia.order.service.OrderMonitorService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

@Service
@SuppressWarnings({"unchecked", "rawtypes"})
@RequiredArgsConstructor
public class OrderMonitorServiceImpl extends ServiceImpl<OrderMonitorMapper, OrderMonitor> implements OrderMonitorService {

    private final OrderMonitorRecordRepository orderMonitorRecordRepository;
    /**
     * 保存订单监控记录到 MongoDB
     * @param orderMonitorRecord
     * @return
     */
    @Override
    public Boolean saveOrderMonitorRecord(OrderMonitorRecord orderMonitorRecord) {
        orderMonitorRecordRepository.save(orderMonitorRecord);
        return true;
    }

    /**
     * 保存订单监控统计记录
     * @param orderMonitor
     * @return
     */
    @Override
    public Long saveOrderMonitor(OrderMonitor orderMonitor) {
        boolean result = this.save(orderMonitor);
        return result ? orderMonitor.getId() : null;
    }

    /**
     * 根据订单 ID 查询订单监控统计记录
     * @param orderId
     * @return
     */
    @Override
    public OrderMonitor getOrderMonitorByOrderId(Long orderId) {
        return this.getOne(new LambdaQueryWrapper<OrderMonitor>().eq(OrderMonitor::getOrderId, orderId));
    }

    /**
     * 更新订单监控统计记录
     * @param orderMonitor
     * @return
     */
    @Override
    public Boolean updateOrderMonitor(OrderMonitor orderMonitor) {
        return this.updateById(orderMonitor);
    }
}
